<template>
	<!-- 必须有根标签 -->
	<view>
		<!-- 搜索热区 -->
		<view class="search-link">
			<view class="inner">
				<icon type="search" size="18" color="#bbb" />
				<text>搜索</text>
			</view>
		</view>
		<!-- 轮播图 -->
		<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay circular>
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<image :src="item.image_src" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- 导航层 -->
		<view class="nav">
			<image v-for="(item,index) in categoryList" :key="index" :src="item.image_src" mode=""></image>
		</view>
		<!-- 楼层 -->
		<view class="floor">
			<view class="floor-item" v-for="(floorItem,index) in floorList" :key="index">
				<image :src="floorItem.floor_title.image_src" mode=""></image>
				<!-- class名中划线分隔 -->
				<view class="product-list">
					<image :src="floorItem.product_list[0].image_src" mode=""></image>
					<view class="right">
						<!-- index为0,转成false;也就是不为0时，就会渲染 -->
						<block v-for="(item,index) in floorItem.product_list.slice(1)" :key="index">
							<image :src="item.image_src" mode=""></image>
						</block>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				categoryList: [],
				floorList: []
			}
		},
		onLoad() {
			this.getSwiperdata()
			this.getCatitems()
			this.getFloordata()
		},
		methods: {
			// 获取楼层数据
			getFloordata() {
				uni.request({
					url: 'https://www.uinav.com/api/public/v1/home/floordata',
					success: (res) => {
						let {
							message,
							meta
						} = res.data
						if (meta.status === 200) {
							this.floorList = message
						}
					}
				})
			},
			// 获取导航栏数据
			getCatitems() {
				uni.request({
					url: 'https://www.uinav.com/api/public/v1/home/catitems',
					success: (res) => {
						let {
							message,
							meta
						} = res.data
						if (meta.status === 200) {
							this.categoryList = message
						}
					}
				})
			},
			// 获取轮播图数据
			getSwiperdata() {
				uni.request({
					url: 'https://www.uinav.com/api/public/v1/home/swiperdata',
					// success(res) {
					// success:function(){
					success: (res) => {
						console.log(res)
						// 如果status为200时,数据才是正确的
						let {
							message,
							meta
						} = res.data
						if (meta.status === 200) {
							this.swiperList = message
						}
						// if (res.data.meta.status === 200) {
						// 	this.swiperList = res.data.message
						// }
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.floor-item {

		// >表示子代
		>image {
			width: 100%;
			height: 88rpx;
		}

		.product-list {
			display: flex;
			padding: 20rpx 17rpx;

			>image {
				height: 386rpx;
				width: 232rpx;
			}

			.right {
				flex: 1;
				display: flex;
				flex-wrap: wrap;

				image {
					height: 188rpx;
					width: 232rpx;
					margin: 0 0 10rpx 10rpx;
				}
			}
		}
	}

	.nav {
		height: 194rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	swiper {
		height: 340rpx;

		image {
			width: 100%;
			height: 340rpx;
		}
	}

	.search-link {
		background-color: #eb4450;
		padding: 20rpx 16rpx;

		.inner {
			height: 60rpx;
			background-color: #fff;
			border-radius: 8rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			icon {
				margin-top: 4rpx;
			}

			text {
				color: #bbb;
				margin-left: 16rpx;
			}
		}
	}
</style>
